package com.blb.community_admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.community_admin.Annotation.Log;
import com.blb.community_admin.entity.vo.ZyOwnerRoomVO;
import com.blb.community_admin.service.ZyOwnerRoomService;
import com.blb.community_admin.util.EasyExcelUtil;
import com.blb.community_admin.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Api(tags = "业主审核")
@RestController
public class ZyOwnerRoomController {
    @Resource
    private ZyOwnerRoomService zyOwnerRoomService;

    /**
     * 模糊查询分页
     * @param current
     * @param size
     * @param
     * @return
     */
    @ApiOperation("查询")
    @PostMapping("/zyOwnerRoom/page")
    public ResponseResult<IPage<ZyOwnerRoomVO>> selectZyOwnerRoomPage(Long current,Long size,@RequestBody ZyOwnerRoomVO zyOwnerRoomVO){
        return ResponseResult.ok(zyOwnerRoomService.selectZyOwnerRoomPage(current,size,zyOwnerRoomVO));
    }

    /**
     * 修改状态
     * @param
     * @return
     */
    @Log(module = "业主审核", operationType = 2, requestMethod = "PUT")
    @ApiOperation("修改状态")
    @PutMapping("/zyOwnerRoom")
    public ResponseResult<String> updateStatus(@RequestBody ZyOwnerRoomVO zyOwnerRoomVO){
        zyOwnerRoomService.updateZyOwnerRoom(zyOwnerRoomVO);
        return ResponseResult.ok("修改成功");
    }

    @Log(module = "业主审核", operationType = 5, requestMethod = "POST")
    @ApiOperation("导出")
    @PostMapping("/zyOwnerRoom/export")
    public ResponseEntity<ByteArrayResource> export(@RequestBody List<ZyOwnerRoomVO> zyOwnerRoomVOS) throws IOException {
        String path = EasyExcelUtil.write("业主房屋数据", ZyOwnerRoomVO.class, zyOwnerRoomVOS);
        ResponseEntity<ByteArrayResource> download = EasyExcelUtil.download(path);
        return download;
    }
}
